package com.burger.counter.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.burger.counter.Constants.SQLConstants;
import com.burger.counter.beans.SignatureBurgerBun;
import com.burger.counter.util.DBConnection;

public class SignatureBurgerBunDao {
	public SignatureBurgerBun[] getSignatureBurgerBunDetails(int regionId){
		Connection con=null;
		ResultSet rs=null;
		PreparedStatement prest =null;
		SignatureBurgerBun SignatureBurgerBunlist[]=null;
		int size;
		try{
			con=DBConnection.getConnection();
			System.out.println("Creating DB Connection");
			String prepStatement=SQLConstants.getSignatureBurgerBun;
			prest = con.prepareStatement(prepStatement);
			prest.setInt(1,regionId);
			
			rs = prest.executeQuery();
			if (rs != null) {
				rs.last();
				size = rs.getRow();
				SignatureBurgerBunlist = new SignatureBurgerBun[size];
				int currRow = 0;
				rs.beforeFirst();

				while (rs.next()) {
					SignatureBurgerBun p = new SignatureBurgerBun();
					p.setSigBurgerBunId(rs.getInt(1));
					p.setSigBurgerBunName(rs.getString(2));
					p.setSigBurgerBunPrice(rs.getDouble(4));
					p.setSigBurgerBunDesc(rs.getString(3));
					SignatureBurgerBunlist[currRow] = p;
					currRow++;
				}
			}		

		}
		catch(Exception e){
			
		}
		
		return SignatureBurgerBunlist;
	}
	
	public void setSignatureBurgerBunCount(int regionId,String SignatureBurgerBunName){
		Connection con=null;
		int rs;
		PreparedStatement prest =null;
		try{
			con=DBConnection.getConnection();
			System.out.println("Creating DB Connection");
			String prepStatement=SQLConstants.updateSignatureBurgerBunCount;
			prest = con.prepareStatement(prepStatement);
			prest.setInt(1,regionId);
			prest.setString(2, SignatureBurgerBunName);
			
			rs = prest.executeUpdate();
			if (rs ==1) {
				System.out.println("signature Burger Bun Count has been updated");
			}					
		}
		catch(Exception e){
			
		}		
	}
}
